#include <cmath>
#include <cstdio>
using namespace std;

long long n;

int main() {
#ifndef ONLINE_JUDGE
#ifdef DEBUG
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef DEBUG
	freopen("select.in", "r", stdin);
	freopen("select.out", "w", stdout);
#endif
#endif
	scanf("%lld", &n);
	long long ans = 0;
	while (n) {
		ans += n - (n >> 1);
		n >>= 2;
	}
	printf("%lld", ans);
	return 0;
}